package com.bodu.wxchat.controller;

import com.bodu.core.common.AbstractCommonController;
import com.bodu.core.entity.ParamReq;
import com.bodu.core.entity.result.PageResult;
import com.bodu.core.entity.result.Result;
import com.bodu.global.security.LoginUserUtil;
import com.bodu.global.annon.TraceLog;
import com.bodu.wxchat.entity.vo.WxchatMiniappConfigVo;
import com.bodu.wxchat.entity.request.WxchatMiniappConfigRequest;
import com.bodu.wxchat.service.WxchatMiniappConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 微信小程序配置 API
 *
 * @author Administrator
 */
@Api(tags = "微信小程序配置 API")
@RestController
@RequestMapping("/wxchatMiniappConfig")
public class WxchatMiniappConfigController extends AbstractCommonController<WxchatMiniappConfigService, WxchatMiniappConfigRequest, WxchatMiniappConfigVo> {

    private final WxchatMiniappConfigService wxchatMiniappConfigService;

    public WxchatMiniappConfigController(WxchatMiniappConfigService wxchatMiniappConfigService) {
        this.wxchatMiniappConfigService = wxchatMiniappConfigService;
    }

    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(wxchatMiniappConfigService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存微信小程序配置")
    public Result<Integer> save(@RequestBody WxchatMiniappConfigRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.save(wxchatMiniappConfigService, request);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新微信小程序配置")
    public Result<Integer> update(@RequestBody WxchatMiniappConfigRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.update(wxchatMiniappConfigService, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("微信小程序配置-查询")
    public Result<List<WxchatMiniappConfigVo>> listPage(@RequestBody ParamReq req) {
        return super.listPage(wxchatMiniappConfigService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("微信小程序配置-统计")
    public Result<Integer> countPage(@RequestBody ParamReq req) {
        return super.countPage(wxchatMiniappConfigService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("微信小程序配置-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<WxchatMiniappConfigRequest> req) {
        return super.page(wxchatMiniappConfigService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除微信小程序配置")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(wxchatMiniappConfigService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除微信小程序配置")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(List<Long> ids) {
        return super.batchDelete(wxchatMiniappConfigService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }

}
